package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.anno.Log;
import org.example.mapper.DeptMapper;
import org.example.pojo.Dept;
import org.example.pojo.Result;
import org.example.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 包名：org.example.controller
 * 用户：admin
 * 日期：2025-09-12
 * 项目名称：pro-demo
 */
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list(){
        log.info("查询全部部门信息");
        List<Dept> deptList =  deptService.list();
        return Result.success(deptList);
    }

    @DeleteMapping("/{id}")
    @Log
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除部门：{}",id);
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    @Log
    public Result save(@RequestBody Dept dept){
        log.info("添加部门:{}",dept);
        deptService.save(dept);
        return Result.success();
    }

    @Log
    @PutMapping("/{id}")
    public Result update(@RequestBody Dept dept){
        log.info("修改部门：{}",dept);
        deptService.update(dept);
        return Result.success();
    }
}
